package com.qianye.service.impl;


import com.qianye.entity.Conversation;
import com.qianye.mapper.ConversationDao;
import com.qianye.service.ConversationCoreService;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (Conversation)表服务实现类
 *
 * @author makejava
 * @since 2024-09-16 23:09:32
 */
@Service("conversationCoreService")
public class ConversationCoreServiceImpl implements ConversationCoreService {
    @Resource
    private ConversationDao conversationDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Conversation queryById(Long id) {
        return this.conversationDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param conversation 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Conversation> queryByPage(Conversation conversation, PageRequest pageRequest) {
        long total = this.conversationDao.count(conversation);
        return new PageImpl<>(this.conversationDao.queryAllByLimit(conversation, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param conversation 实例对象
     * @return 实例对象
     */
    @Override
    public Conversation insert(Conversation conversation) {
        this.conversationDao.insert(conversation);
        return conversation;
    }

    /**
     * 修改数据
     *
     * @param conversation 实例对象
     * @return 实例对象
     */
    @Override
    public Conversation update(Conversation conversation) {
        this.conversationDao.update(conversation);
        return this.queryById(conversation.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.conversationDao.deleteById(id) > 0;
    }
}
